﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Database;
using Communication;

namespace WebApplication1
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "WebWCFService" in code, svc and config file together.
    public class WebWCFService : IClientCommunication
    {

        int forum;
        IServerCommunication serverCommunication;
        _Default web;

        public WebWCFService(_Default web)
        {
            InitCommunication();
            this.web = web;
            this.forum = 1;
            //probably need to add a call to enter a certain forum here
            System.Console.WriteLine("web connected");
        }

        public void InitCommunication()
        {
            DuplexChannelFactory<IServerCommunication> communicationFactory =
                  new DuplexChannelFactory<IServerCommunication>(
                      new InstanceContext(this),
                      new NetTcpBinding(),
                      new EndpointAddress("net.tcp://localhost:8000/ISubscribe"));
            try
            {
                serverCommunication = communicationFactory.CreateChannel();
            }
            catch (Exception e)
            {
                System.Console.WriteLine("Couldn't establish a connection");
            }
        }



        public void GetForum()
        {
            this.serverCommunication.Login("guest", "", null, forum);
            this.serverCommunication.GetForum2(forum);

        }



        void IClientCommunication.ReceiveJoin(User client, bool ans, string systemMsg)
        {
            throw new NotImplementedException();
        }

        public void ReceiveLogout()
        {
            throw new NotImplementedException();
        }

        public void ReceiveNotify(string notifyMsg)
        {
            throw new NotImplementedException();
        }

        public void ReceiveForumUsersList(List<User> uList)
        {
            throw new NotImplementedException();
        }

        public void ReceiveSystemUsersList(List<string> uList)
        {
            throw new NotImplementedException();
        }

        public void AutherizationError()
        {
            throw new NotImplementedException();
        }

        void IClientCommunication.ReceiveForum(Forum forum)
        {
            this.web.getForum(forum.getTitle());
        }

        public void ReceiveSubForum(SubForum subforum)
        {
            throw new NotImplementedException();
        }

        public void ReceiveThread(Thread thread)
        {
            throw new NotImplementedException();
        }

        public void ReceiveSystemStatistics(string stats, User me)
        {
            throw new NotImplementedException();
        }

        public void ReceiveForumStatistics(string stats)
        {
            throw new NotImplementedException();
        }

        public void RecieveError(string error)
        {
            throw new NotImplementedException();
        }

        public void RecieveCodeConfirm()
        {
            throw new NotImplementedException();
        }
    }
}
